<include file="Public:header"/>
<div class="top_title">
	<h1 class="tc">支付订单</h1>
</div>

<section class="bd bd_p0">		
	<div class="member">
		<div class="order_detail">
			<div class="block">
				<div class="content">
					<ul>
						<li><span>订单号：</span>{$info['order_sn']}</li>
						<li><span>合同名称：</span>{$info['title']}</li>
						<li class="red"><span>支付金额：</span><strong>￥{$info['order_amount']}</strong>元</li>
					</ul>
				</div>
			</div>
		</div>
	</div>
</section>
<div class="list_order">
	<div class="operate" style="text-align: center;">
		<a class="btn_red weixin-pay nojump" style="float: none;display: inline-block;font-size: 0.8rem;width: 5rem;">支付</a>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
	$('.weixin-pay').click(function () {
		ajax_weixin_pay();
	})
	<eq name="is_weixin_pay" value="1">
		ajax_weixin_pay();
	</eq>
})

function ajax_weixin_pay() {
	loading();
	$.ajax({
		type    : 'get',
		url     : '{:U("Order/get_weixin_pay_params", array("order_sn"=>$order_sn))}',
		success : function(json){
			removeLoading();
			if(json.status == 1){
				weixin_pay(json.data);
			}
			else if(json.url){
				location.href = json.url;
			}else{
				msgbox(json.info, 'error');
			}
		},
		error : function (data) {
			removeLoading();
			msgbox('请求失败，请稍候再试！','error');
		}
	});
}
//启用微信支付
function weixin_pay (pay_params) {
	if (typeof WeixinJSBridge == "undefined"){
		if( document.addEventListener ){
			document.addEventListener('WeixinJSBridgeReady', weixin_pay_call(pay_params), false);
		}else if (document.attachEvent){
			document.attachEvent('WeixinJSBridgeReady', weixin_pay_call(pay_params));
			document.attachEvent('onWeixinJSBridgeReady', weixin_pay_call(pay_params));
		}
	}else{
		weixin_pay_call(pay_params);
	}
}
//微信支付调用
function weixin_pay_call (pay_params) {
	// alert(pay_params);
	pay_params = jQuery.parseJSON(pay_params);
	WeixinJSBridge.invoke(
		'getBrandWCPayRequest',
		pay_params,
		function(res){
			//支付成功处理
			if(res.err_msg == "get_brand_wcpay_request:ok" ) {
				location.href = '{:U("UserOrder/detail", array("order_sn"=>$order_sn))}?showwxpaytitle=1';
			}
			//支付过程中用户取消处理
			else if(res.err_msg == "get_brand_wcpay_request:cancel" ) {
				msgbox('您已取消支付！','wran','{:U("Order/pay", array("order_sn"=>$order_sn))}?showwxpaytitle=1');
			}
			//支付失败处理
			else if(res.err_msg == "get_brand_wcpay_request:fail" ) {
				msgbox('支付失败！','wran','{:U("Order/pay", array("order_sn"=>$order_sn))}?showwxpaytitle=1');
			}
			//出错处理
			else{
				msgbox(res.err_msg);
			}
		}
	);
}
</script>
<include file="Public:footer"/>